/* $Header: sig_tbls.c,v 2.2 01/10/02 10:29:23 przybyls Exp $ */

/* sig_tbls.c - workfile get/set for the signal path setpoints */
/* Bob Cook; Feb 1993 */
/* Copyright (c) 1993, Hewlett-Packard Co. */


#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <ramps.h>
#include <zone_config.h>
#include <zone_status.h>
#include <status.h>
#include <error.h>
#include <sig_types.h>
#include <sigpath.h>
#include <sig_ui.h>
#include <dig_path.h>



#include  <method.h>
/*
#include  <typedefs.h>
#include  <error.h>
#include  <config.h>
#include  <method.h>
#include  <stddef.h>


#include <sig_types.h>
#include <sig_ui.h>
*/


/********************* wrapper function prototypes *********************/
/*
 * Format:
 *    Get commands:
 *        mGetWrapperCommand(void *parameter, U_INT8 number)
 *    Set commands:
 *        mSetWrapperCommand(void *parameter, INT32 setpoint, U_INT8 number)
 *    Examples:
 *       parameter - 4 byte parameter that is passed to the wrapper function
 *                  (use: pointer to type of zone - oven, detector or inlet)
 *                  (use: indicate signal 1 or signal 2)
 *       setpoint - value of setpoint from received command
 *       number - may be used for anything (such as ramp number)
 */

static INT32   mGetSignalRange(void *parm, U_INT8 num);
static INT32   mGetFastPeaksOnOff(void *parm, U_INT8 num);
static INT32   mGetSignalAttn(void *parm, U_INT8 num);

static INT32   mGetSignalZeroOnOff(void *parm, U_INT8 num);
static INT32   mGetSignalZero(void *parm, U_INT8 num);

static INT32   mGetSignalScaleMultiplier(void *parm, U_INT8 num);
static INT32   mGetSignalScaleDivisor(void *parm, U_INT8 num);
static INT32   mGetSignalSigDigits(void *parm, U_INT8 num);
static INT32   mGetSignalScaleLabel(void *parm, U_INT8 num);


static UI_ERR  mSetSignalRange(void *parm, INT32 setpt, U_INT8 num);
static UI_ERR  mSetFastPeaksOnOff(void *parm,INT32 setpt,U_INT8 num);
static UI_ERR  mSetSignalAttn(void *parm,INT32 setpt,U_INT8 num);

static UI_ERR  mSetSignalZeroOnOff(void *parm,INT32 setpt,U_INT8 num);
static UI_ERR  mSetSignalZero(void *parm,INT32 setpt,U_INT8 num);

static UI_ERR  DummyFunction(void *which);
static UI_ERR  DummySet(void *parm,INT32 setpt,U_INT8 num);

/********************* command table entries *********************/
/*
 * Format:
 *   static const METHCMD_ENTRY mmCommandTableEntries[] =
 *   {
 *     {mGetWrapperCommand, mSetWrapperCommand, number, type of setpoint}
 *   }
 *          number - may be used for anything (such as ramp number)
 *          type of setpoint -
 *                    METH_INT0   - XXX
 *                    METH_INT1   - XX.X
 *                    METH_INT2   - X.XX
 *                    METH_ON_OFF - 1 or 0
 *                    METH_HEX
 *                    METH_STR
 */

static const METHCMD_ENTRY mmSxCA[] =
{
        {mGetSignalRange, mSetSignalRange,0,METH_INT0},
        {mGetFastPeaksOnOff,mSetFastPeaksOnOff,0,METH_ON_OFF},
        {mGetSignalAttn,mSetSignalAttn,0,METH_INT0},
};


static const METHCMD_ENTRY mmSxZA[] =
{
        {mGetSignalZeroOnOff,mSetSignalZeroOnOff,0,METH_ON_OFF},
        {mGetSignalZero,mSetSignalZero,0,METH_INT0},
};

static const METHCMD_ENTRY mmSxSF[] =
{
        {mGetSignalScaleMultiplier, DummySet, 0, METH_INT0},
        {mGetSignalScaleDivisor,    DummySet, 0, METH_INT0},
        {mGetSignalSigDigits,       DummySet, 0, METH_INT0},
        {mGetSignalScaleLabel,      DummySet, 0, METH_STR},
};


/********************* command tables *********************/
/*
 * Format:
 *   const METHCMD mCommandTable[] =
 *   {
 *      MAXINDEX(mmCommandTableEntries, METHCMD_ENTRY),
 *      &mmCommandTableEntries[starting_index_in_table],
 *      parameter,
 *      PreCommandFunction,
 *      PostCommandFunction
 *   }
 */

const METHCMD mS1CA =
{
        MAXINDEX(mmSxCA, METHCMD_ENTRY),
        &mmSxCA[0],
        (void *)SIGNAL1,
        DummyFunction,
        DummyFunction
};

const METHCMD mS2CA =
{
        MAXINDEX(mmSxCA, METHCMD_ENTRY),
        &mmSxCA[0],
        (void *)SIGNAL2,
        DummyFunction,
        DummyFunction
};

const METHCMD mSPCA =
{
        MAXINDEX(mmSxCA, METHCMD_ENTRY),
        &mmSxCA[0],
        (void *)SIGNALP,
        DummyFunction,
        DummyFunction
};


const METHCMD mS1ZA =
{
        MAXINDEX(mmSxZA, METHCMD_ENTRY),
        &mmSxZA[0],
        (void *)SIGNAL1,
        DummyFunction,
        DummyFunction
};

const METHCMD mS2ZA =
{
        MAXINDEX(mmSxZA, METHCMD_ENTRY),
        &mmSxZA[0],
        (void *)SIGNAL2,
        DummyFunction,
        DummyFunction
};

const METHCMD mSPZA =
{
        MAXINDEX(mmSxZA, METHCMD_ENTRY),
        &mmSxZA[0],
        (void *)SIGNALP,
        DummyFunction,
        DummyFunction
};

/* S1xxSF, S2xxSF: Scale factor commands */

const METHCMD mS1SF =
{
        MAXINDEX(mmSxSF, METHCMD_ENTRY),
        &mmSxSF[0],
        (void *)pSIGNAL1,
        DummyFunction,
        DummyFunction
};


const METHCMD mS2SF =
{
        MAXINDEX(mmSxSF, METHCMD_ENTRY),
        &mmSxSF[0],
        (void *)pSIGNAL2,
        DummyFunction,
        DummyFunction
};


const METHCMD mSPSF =
{
        MAXINDEX(mmSxSF, METHCMD_ENTRY),
        &mmSxSF[0],
        (void *)pSIGNALP,
        DummyFunction,
        DummyFunction
};


/********************* "get" wrapper functions *********************/

static UI_ERR DummyFunction(void *which)
{
        (void) which;
        return OK;
}

static UI_ERR  DummySet(void *parm,INT32 setpt,U_INT8 num)
{
        (void) parm;
        (void) setpt;
        (void) num;
        return OK;
}





static INT32   mGetSignalRange(void *parm, U_INT8 num)
{
        (void) num;
        return  GetSignalRange( (parm == SIGNAL1) ? pSIGNAL1 :
                                (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP );
}


static INT32   mGetFastPeaksOnOff(void *parm, U_INT8 num)
{
        (void) num;
        if(GetFastPeaks((parm == SIGNAL1)?pSIGNAL1:
                        (parm == (void *)SIGNAL2)?pSIGNAL2:pSIGNALP ) == DAC_RATE_30HZ)
        {
           return 1;
        }
        else
        {
           return 0;
        }
}

static INT32   mGetSignalAttn(void *parm, U_INT8 num)
{
        (void) num;
        return  GetSignalAttn( (parm == SIGNAL1) ? pSIGNAL1 :
                               (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP );
}


static INT32   mGetSignalZeroOnOff(void *parm, U_INT8 num)
{
        (void) num;
        if( GetSignalZeroOnOff( (parm == SIGNAL1) ? pSIGNAL1 :
                                (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP ) == ON)
        {
           return 1;
        }
        else
        {
           return 0;
        }
}

static INT32   mGetSignalZero(void *parm, U_INT8 num)
{
     (void) num;
     return  GetSignalZero( (parm == SIGNAL1) ? pSIGNAL1 :
                            (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP );
}


static INT32   mGetSignalScaleMultiplier(void *parm, U_INT8 num)
{
     (void) num;
     return  GetSignalScaleMultiplier( parm );
}

static INT32   mGetSignalScaleDivisor(void *parm, U_INT8 num)
{
     (void) num;
     return  GetSignalScaleDivisor( parm );
}

static INT32   mGetSignalSigDigits(void *parm, U_INT8 num)
{
     (void) num;
     return  (INT32)GetSignalUnits( parm );
}

static INT32   mGetSignalScaleLabel(void *parm, U_INT8 num)
{
     (void) num;
     return  GetSignalScaleLabel( parm );
}


/********************* "set" wrapper functions *********************/




static UI_ERR  mSetSignalRange(void *parm, INT32 setpt, U_INT8 num)
{

   (void) num;
   return  SetSignalRange( ((parm == SIGNAL1) ? pSIGNAL1 :
                            (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP) , setpt );
}

static UI_ERR  mSetFastPeaksOnOff(void *parm,INT32 setpt,U_INT8 num)
{
   (void) num;
   if ((ON_OFF) setpt == ON)
   {
      return  SetFastPeaks((parm==SIGNAL1)? pSIGNAL1 :
                           (parm==(void *)SIGNAL2)? pSIGNAL2 : pSIGNALP,DAC_RATE_30HZ);
   }
   else
   {
      return  SetFastPeaks((parm==SIGNAL1)? pSIGNAL1 :
                           (parm==(void *)SIGNAL2)? pSIGNAL2 : pSIGNALP,DAC_RATE_3HZ);
   }
}

static UI_ERR  mSetSignalAttn(void *parm,INT32 setpt,U_INT8 num)
{

   (void) num;
   return  SetSignalAttn( ((parm == SIGNAL1) ? pSIGNAL1 :
                           (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP) , setpt );
}


static UI_ERR  mSetSignalZeroOnOff(void *parm,INT32 setpt,U_INT8 num)
{
   (void) num;

   if ( (ON_OFF)setpt == OFF )
   {
      return  SetSignalZeroOff( (parm == SIGNAL1) ? pSIGNAL1 :
                                (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP );
   }
   else
   {
      return SetSignalZeroOn( (parm == SIGNAL1) ? pSIGNAL1 :
                              (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP );
   }

}


static UI_ERR  mSetSignalZero(void *parm,INT32 setpt,U_INT8 num)
{
   (void) num;
   return  SetSignalZero( ((parm == SIGNAL1) ? pSIGNAL1 :
                           (parm == (void *)SIGNAL2) ? pSIGNAL2 : pSIGNALP) , setpt );
}
